Schemas validation while running base44 dev#395
Conversation
| @@ -1,5 +1,5 @@ | |||
| import { resolve } from "node:path"; | |||
| import { defineConfig } from "vitest/config"; | |||
| import { resolve } from "path"; | |||
There was a problem hiding this comment.
not related to PR, just cleaning up some linting
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/cli@0.0.44-pr.395.5afac9aPrefer not to change any import paths? Install using npm alias so your code still imports npm i "base44@npm:@base44-preview/cli@0.0.44-pr.395.5afac9a"Or add it to your {
"dependencies": {
"base44": "npm:@base44-preview/cli@0.0.44-pr.395.5afac9a"
}
}
Preview published to npm registry — try new features instantly! |
847df50 to
e91f0a6
Compare
There was a problem hiding this comment.
Just moved to a new location, inside db directory
| delete: RLSRuleSchema.optional(), | ||
| }); | ||
|
|
||
| const PropertyDefinitionSchema: z.ZodType<unknown> = z.looseObject({ |
There was a problem hiding this comment.
I don't see reason for it to be unknown when types are casted.
(same below)
Am i I missing something?
|
@claude review |
|
Claude finished @artemdemo's task in 1m 56s —— View job PR Review: Schemas Validation
Overall this is a clean, well-structured addition. The Issues1.
|
devbase44 dev
| "object", | ||
| ]; | ||
|
|
||
| export class Validator { |
There was a problem hiding this comment.
This is a high level idea, haven't dived into it -
But as far as i understand the entities schema are basically json-schema standard, and i saw this package @cfworker/json-schema (https://github.com/cfworker/cfworker) which we can feed the schema to and then just call validate?
There was a problem hiding this comment.
The thing is that leaders don't really want to validate - this schema is just documentation of intent
And looks we're going with this approach forward.
json-schema supports far more features than what we need to handle.
Therefore not sure if need to introduce anything that will actually use this schema to validate any further than just types.
There was a problem hiding this comment.
Looked into it once more.
It's possible to use json-schema, not sure if makes code simpler though.
I will still need to do recursions in order to make json-schema work with limited set of validations.
And also I will need to filter out errors that are not relevant to our case.
If you want to take a look, here is a prompt that I used to test it out:
Take a look at how I validate using a schema. Basically, I am only interested in the property type and whether it's required or not. I don't validate other constraints like maxLength, pattern, minLength, etc. I do validate recursively, though. If a property is an object or an array, I will go and check its properties/items, but will only validate the same two things: type and whether it's required. So, I'm thinking whether I can use `@cfworker/json-schema` instead for the same thing. This package does much more, but maybe I can silence other errors or something.
There was a problem hiding this comment.
I think we should proceed with the current implentation considering the links you added, I just don't love maintaining this validation logic (and issues that may raise) on the CLI side.. but it looks kinda simple for now 👍
There was a problem hiding this comment.
we will need anyway maintain validation logic in some capacity 😞
kfirstri
left a comment
There was a problem hiding this comment.
looks good, what do you think about https://github.com/cfworker/cfworker as a validator?
Note
Description
This PR adds entity record validation to the dev server, introducing a
Validatorclass that enforces entity schemas on create and update operations. When a record fails validation (wrong types, missing required fields), the API now returns a422 Unprocessable Entityresponse with a structured error object — matching the shape of production API validation errors. TheDatabaseclass is also reorganized into adb/subdirectory to better group schema-aware logic.Related Issue
None
Type of Change
Changes Made
packages/cli/src/cli/dev/dev-server/db/validator.ts— newValidatorclass withfilterFields(),applyDefaults(), andvalidate()methods supporting all Base44 field types (string,integer,number,boolean,array,object), required-field checks, partial validation, and recursive nested type validationpackages/cli/src/cli/dev/dev-server/db/database.ts— refactoredDatabaseclass (moved fromdatabase.ts) that now stores entity schemas and exposesvalidate()andprepareRecord()methodspackages/cli/src/cli/dev/dev-server/database.ts— replaced bydb/database.tsroutes/entities.ts— POST (single and bulk) and PATCH handlers now calldb.prepareRecord()+db.validate()before inserting/updating; invalid records return422with aValidationErrorbodycore/resources/entity/schema.ts— exportedPropertyDefinitiontype, madetypefield required (was optional), and cleaned up recursive Zod type annotationspackages/cli/tests/scripts/validator.spec.ts— comprehensive unit test suite for theValidatorclass covering all field types, required fields, partial validation, nested arrays/objects, defaults, and error shapesvitest.config.tsto usenode:pathimport; addedbiome-ignorecomment in connector testTesting
npm test)Checklist
docs/(AGENTS.md) if I made architectural changesAdditional Notes
The validator intentionally silently ignores unknown fields (relying on
filterFields()to strip them beforehand) and skipsitems/propertiessub-validation when those schema keys are absent, with inline test comments noting this matches current production behavior.🤖 Generated by Claude | 2026-03-11 00:00 UTC